<template>
  <div id="wrapper">
    <img id="logo" src="~@/assets/logo.png" alt="ANDS" />
    <main>
      <div class="left-side">
        <span class="title">视频输出位置</span>
      </div>

      <div class="right-side">
        <div class="doc">
          <button
            @click="
              open('https://simulatedgreg.gitbooks.io/electron-vue/content/')
            "
          >打开视频文件</button>
          <br />
          <br />
        </div>
        <div class="doc">
          <button class="alt" @click="gotolink">参数设置</button>
          <button class="alt" @click="open('https://vuejs.org/v2/guide/')">退出</button>
          <br />
          <br />
        </div>
        <div class="doc">
          <button class="alt" @click="startBackendDemo">手动指定</button>
          <button class="alt" @click="stopBackendDemo">重新检测</button>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import { processVideo } from '../../lib/api.mjs';
import { startBackend, stopBackend } from '../../lib/backend.mjs';

export default {
  name: 'landing-page',
  data() {
    return {
      processVideoPending: false,
    };
  },
  methods: {
    gotolink() {
      this.$router.replace('/options');
    },
    open(link) {
      this.$electron.shell.openExternal(link);
    },
    async processVideoDemo() {
      console.log('开始处理');
      this.processVideoPending = true;
      try {
        const { outFile } = await processVideo(
          'res/videoResultsMock.avi',
          15,
          25,
          {
            // 此形式的参数都是可选参数，下面显示了其默认值，参数说明详见 JSDoc
            resultsDir: '.',
            samplingRate: 400,
            alpha: 15,
            sigma: 3,
            pyrType: 'octave',
            videoScale: 1,
          },
        );
        console.log('outFile', outFile);
        alert(`输出文件名：${outFile}`);
      } catch (error) {
        console.error('error', error);
        alert(`错误：${error.message}`);
      } finally {
        this.processVideoPending = false;
        console.log('处理完成');
      }
    },
    startBackendDemo() {
      console.log('尝试启动后端...');
      startBackend();
    },
    stopBackendDemo() {
      console.log('尝试停止后端...');
      stopBackend();
    },
  },
};
</script>

<style>
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

#wrapper {
  background: radial-gradient(
    ellipse at top left,
    rgba(255, 255, 255, 1) 40%,
    rgba(229, 229, 229, 0.9) 100%
  );
  height: 100vh;
  padding: 60px 80px;
  width: 100vw;
}

#logo {
  height: auto;
  margin-bottom: 10px;
  width: 420px;
}

main {
  display: flex;
  justify-content: space-between;
}

main > div {
  flex-basis: 50%;
}

.title {
  color: #2c3e50;
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 6px;
}

.title.alt {
  font-size: 18px;
  margin-bottom: 10px;
}

.doc button {
  font-size: 0.8em;
  cursor: pointer;
  outline: none;
  padding: 0.75em 2em;
  border-radius: 2em;
  display: inline-block;
  color: #fff;
  background-color: #4fc08d;
  transition: all 0.15s ease;
  box-sizing: border-box;
  border: 1px solid #4fc08d;
}

.doc button.alt {
  color: #42b983;
  background-color: transparent;
}
</style>
